/*
  odds to decibels

 * Copyleft jeff cliff 2005
 *
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or (at
 *      your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful, but
 *      WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *      General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

double DOUBLE_MIN = 1e-3240L;

using namespace std;

double oddsToDb(double);
int oddsdriver(int, char** );
void oddsToDb(double, double, double&, double&);

int main(int argc, char** argv) 
{
  return oddsdriver(argc, argv);
}

int oddsdriver(int argc, char** argv)
{
  if (!(argc==3))
    {
      cout << "usage:" << endl
	   << "o2d odds plusminus" << endl; 
	return 1;
    }
  else
    {
      double r, dr;
      oddsToDb(atof(argv[1]),atof(argv[2]),r,dr);
      cout << setprecision(9) << r << "+/-" << dr;
      return 0;
    }
 }

void oddsToDb(double in, double plusMinusIn, double& out, double& plusMinusOut)
{ 
  double min = oddsToDb(in+plusMinusIn);
  double max = oddsToDb(in-plusMinusIn);
  out = (min+max)/2.0;
  plusMinusOut = abs(max-min)/2.0;
}

double oddsToDb(double in)
{ 
  double out = 0;
  out = log10 ( in / 10 );
  return out;
}

